package com.sfc.spiderweb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sfc.spiderweb.entity.param.AmazonScreenshotParam;
import com.sfc.spiderweb.entity.po.AmazonScreenshot;
import com.sfc.spiderweb.mapper.AmazonScreenshotMapper;
import com.sfc.spiderweb.service.AmazonScreenshotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AmazonScreenshotServiceImpl extends ServiceImpl<AmazonScreenshotMapper, AmazonScreenshot> implements AmazonScreenshotService {

    @Autowired
    private AmazonScreenshotMapper mapper;

    @Override
    public Page<AmazonScreenshot> getPage(AmazonScreenshotParam param) {
        Page<AmazonScreenshot> page = new Page<>(param.getCurrent(), param.getSize());
        QueryWrapper<AmazonScreenshot> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(param.getAccount())) {
            wrapper.lambda().eq(AmazonScreenshot::getAccount, param.getAccount());
        }
        if (!StringUtils.isEmpty(param.getStartScreenshotDate())) {
            wrapper.lambda().ge(AmazonScreenshot::getScreenshotDate, param.getStartScreenshotDate());
        }
        if (!StringUtils.isEmpty(param.getEndScreenshotDate())) {
            wrapper.lambda().le(AmazonScreenshot::getScreenshotDate, param.getEndScreenshotDate());
        }
        wrapper.lambda().eq(AmazonScreenshot::getStatus, "1");
        Page<AmazonScreenshot> amazonTransferPage = mapper.selectPage(page, wrapper);
        return amazonTransferPage;
    }
}
